package com.insurance.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.insurance.common.enums.DeleteFlagEnum;
import com.insurance.dao.PartnerRoleDao;
import com.insurance.entity.PartnerRoleEntity;
import com.insurance.service.PartnerRoleService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.insurance.common.utils.PageUtils;
import com.insurance.common.utils.Query;




@Service("partnerRoleService")
public class PartnerRoleServiceImpl extends ServiceImpl<PartnerRoleDao, PartnerRoleEntity> implements PartnerRoleService {

    @Override
    public PageUtils queryPage(Map<String, Object> params, QueryWrapper<PartnerRoleEntity> queryWrapper) {
        IPage<PartnerRoleEntity> page = this.page(
                new Query<PartnerRoleEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }

    @Override
    public QueryWrapper<PartnerRoleEntity> getQueryWrapper(PartnerRoleEntity partnerRoleEntity){
        QueryWrapper<PartnerRoleEntity> queryWrapper = new QueryWrapper<PartnerRoleEntity>();
        queryWrapper.eq("delete_flag", String.valueOf(DeleteFlagEnum.UN_DELETE.getCode()));
        if(!StringUtils.isBlank(partnerRoleEntity.getRoleName())){
            queryWrapper.like("role_name", partnerRoleEntity.getRoleName());
        }
        return queryWrapper;
    }

    @Override
    public boolean removeBatch(List<String> roleIdList, PartnerRoleEntity partnerRoleEntity){
        if(CollectionUtil.isEmpty(roleIdList)){
            return true;
        }
        QueryWrapper<PartnerRoleEntity> queryWrapper = getQueryWrapper(new PartnerRoleEntity());
        queryWrapper.in("role_id", roleIdList);
        return this.update(partnerRoleEntity, queryWrapper);
    }

    @Override
    public List<PartnerRoleEntity> queryList(PartnerRoleEntity partnerRoleEntity){
        QueryWrapper<PartnerRoleEntity> queryWrapper = getQueryWrapper(partnerRoleEntity);
        return this.list(queryWrapper);
    }

    @Override
    public List<PartnerRoleEntity> queryList(QueryWrapper<PartnerRoleEntity> queryWrapper){
        return this.list(queryWrapper);
    }

}